package web.servlet;

import domain.Account;
import service.AccountService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "CheckUseridServlet", urlPatterns = {"/CheckUserid"})
public class CheckUseridServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Account loginUser = (Account) req.getSession().getAttribute("loginUser");
        String type = req.getParameter("type");
        String id = req.getParameter("userid");
        if(type.equals("change") && loginUser != null && id.equals(loginUser.getUserid())){
            return;
        }

        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();
        if(new AccountService().findUserById(id)){
            out.print("Exist");
        }
    }
}
